﻿using System.Security.Cryptography;
using System.Text;

namespace YouShuCode.Utils
{
    public static class SHA256Extension
    {
        public static string ToSHA256(this string sourceString)
        {
            byte[] bytValue = Encoding.UTF8.GetBytes(sourceString);
            SHA256 sha256 = new SHA256CryptoServiceProvider();

            byte[] retVal = sha256.ComputeHash(bytValue);
            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < retVal.Length; i++)
            {
                sb.Append(retVal[i].ToString("x2"));
            }
            return sb.ToString();
        }
    }
}
